package com.nstar.base.controls
{
	import mx.containers.Canvas;
	import mx.events.FlexEvent;
	import mx.controls.Image;
	import com.nstar.base.assets.Assets;
	import mx.utils.ObjectUtil;
	import flash.events.Event;
	import mx.core.ScrollPolicy;

	/**
	 * 图片数字组件
	 * 用图片来代替数字来显示
	 * 
	 * 
	 */ 
	public class ImageNumber extends Canvas
	{
		private var _number:String;//数字串
		private var _size:int =8;//默认大小为8
		
		private var _distanceWidth:int;
		private var _distanceHeight:int;
		
		public function ImageNumber()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		public function set size(value:int):void{
			this._size = value;
			_distanceWidth = _size * 2;
			_distanceHeight = _size * 3;
		}
		
		public function get size():int{
			return this._size;
		}
		
		public function set number(value:String):void{
			this._number = value;
		}
		
		public function get number():String{
			return this._number;
		}
		
		private function init(event:FlexEvent):void{
			this.setStyle("backgroundColor",0x000000);
			this.horizontalScrollPolicy = ScrollPolicy.OFF;
			this.verticalScrollPolicy = ScrollPolicy.OFF;
		}
		
		//添加图片到Canvas中
		public function refresh():void{
			this.removeAllChildren();
			for(var i:int=0;i<_number.length;i++){
				var n:int = int(_number.substr(i,1));
				var img:Image = imageN(n);
				this.addChild(img);
				img.x = i*_distanceWidth;
				img.y = 0;
				img.width = _distanceWidth;
				img.height = _distanceHeight;
			}
		}
		
		
		private function imageN(value:int):Image{
			var img:Image = new Image();
			switch (value){
				case 0:
					img.source = Assets.number0;break;
				case 1:
					img.source = Assets.number1;break;
				case 2:
					img.source = Assets.number2;break;
				case 3:
					img.source = Assets.number3;break;
				case 4:
					img.source = Assets.number4;break;
				case 5:
					img.source = Assets.number5;break;
				case 6:
					img.source = Assets.number6;break;
				case 7:
					img.source = Assets.number7;break;
				case 8:
					img.source = Assets.number8;break;
				case 9:
					img.source = Assets.number9;break;
				default:
					img.source = Assets.number0;break;
			}
			return img;
		}
		
		
		
	}
}